import request from '@/utils/request';
import { ProfitSharingTemplateRelation } from '@/types/profit';

// 创建分账模板关联
export function createRelation(data: ProfitSharingTemplateRelation) {
  return request.post('/api/profit/sharing/template/relation/create', data);
}

// 更新分账模板关联
export function updateRelation(id: number, data: ProfitSharingTemplateRelation) {
  return request.put(`/api/profit/sharing/template/relation/update/${id}`, data);
}

// 删除分账模板关联
export function deleteRelation(id: number) {
  return request.delete(`/api/profit/sharing/template/relation/delete/${id}`);
}

// 获取分账模板关联列表
export function getRelationList(params: {
  pageNum: number;
  pageSize: number;
  templateId?: number;
  chargingGroupId?: number;
  partnerId?: number;
}) {
  return request.get('/api/profit/sharing/template/relation/list', params);
}

// 根据模板ID获取关联列表
export function getRelationsByTemplateId(templateId: number) {
  return request.get(`/api/profit/sharing/template/relation/template/${templateId}`);
}

// 根据站点ID获取关联信息
export function getRelationByChargingGroupId(chargingGroupId: number) {
  return request.get(`/api/profit/sharing/template/relation/charging-group/${chargingGroupId}`);
}

// 根据合伙人ID获取关联信息
export function getRelationByPartnerId(partnerId: number) {
  return request.get(`/api/profit/sharing/template/relation/partner/${partnerId}`);
} 